package com.xuhuan.demo.pattern.decorator;

import com.xuhuan.demo.pattern.decorator.coffee.LongBlackCoffee;
import com.xuhuan.demo.pattern.decorator.decorator.Chocolate;
import com.xuhuan.demo.pattern.decorator.decorator.Milk;

/**
 * @author huan.xu
 * @date 2021/10/6 23:12
 * @description
 */
public class CoffeeBar {

    public static void main(String[] args) {
        //装饰者模式下的订单: 2份巧克力 + 一份牛奶的 LongBlack
        //1. 一份LongBlack
        Drink order = new LongBlackCoffee();
        //2. 加一份牛奶
        order = new Milk(order);
        //3. 加一份巧克力
        order = new Chocolate(order);
        //4. 加一份巧克力
        order = new Chocolate(order);

        printOrder(order);
    }

    /**
     * 打印订单信息
     *
     * @param order
     */
    private static void printOrder(Drink order) {
        StringBuilder builder = new StringBuilder("");
        builder.append("订单：")
                .append(order.getDescription())
                .append("，总共：")
                .append(order.cost())
                .append("元");
        System.out.println(builder.toString());
    }


}
